<?php
/**
 * Created by PhpStorm.
 *
 * Author : Traveler.
 * Time   : 2020/3/2 11:57
 * Company: Inner Mongolia Zhengzhi Network Technology Co., Ltd
 */

namespace app\admin\model;


use app\admin\BaseModel;

class IcafeWan extends BaseModel
{
    /**
     * 数据表名称
     * @var string
     */
    protected $table = 'ibms_icafe_wan';

    /**
     * 查询字段
     * @var array
     */
    protected $query = [
        'id'         => '=',
        'icafe_id'   => '=',
        'isp_id'     => '=',
        'bandwidth'  => '=',
        'ipaddress'  => '=',
        'mask'       => '=',
        'gateway'    => '=',
    ];

    /**
     * (静态)获取表格渲染数据
     * @param array $param     请求参数
     * @param bool  $isdeleted 删除标记
     * @return array
     */
    public static function getIcafeWanTable(array $param = [], bool $isdeleted = false)
    {
        $model  = new static;
        $with   = ['icafeIsp'];
        $where  = [['delete_time', $isdeleted ? '>' : '=', 0]];
        $filter = $model->filterParam($param, $where);

        return [
            'data'  => $model->where($filter['where'])->with($with)->order('id')->page($filter['page'], $filter['limit'])->select(),
            'count' => $model->where($filter['where'])->count()
        ];
    }

    /**
     * 模型关联：运营商
     * @return \think\model\relation\BelongsTo
     */
    public function icafeIsp()
    {
        return $this->belongsTo(IcafeIsp::class, 'isp_id');
    }
}